Skip to content

fix: Adapt new visualizer version #4025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from

Conversation

AlejandroFernandezLuces
Copy link
Contributor

@AlejandroFernandezLuces AlejandroFernandezLuces commented Jun 20, 2025

Description

Adapt PyMAPDL visualizer to 0.10.0 version of the ansys visualization tool.

Issue linked

Breaking change in visualization tool: ansys/ansys-tools-visualization-interface#306

Checklist

Summary by Sourcery

Adapt plotting methods to the updated visualization interface by removing deprecated keyword arguments from show() calls and upgrade the ansys-tools-visualization-interface dependency to 0.10.0.

Enhancements:

  • Remove **kwargs from pl.show() and backend.show() invocations across all plot methods to comply with the new visualizer API

Build:

  • Bump ansys-tools-visualization-interface from 0.9.2 to 0.10.0 in dev and documentation dependencies

Summary by Sourcery

Adapt PyMAPDL plotting to the breaking changes in ansys-tools-visualization-interface 0.10.0 by removing deprecated **kwargs from show() calls, extracting and forwarding explicit parameters (return_plotter, return_cpos, savefig, cpos) in all plot methods, and bump the visualization-interface dependency accordingly.

Enhancements:

  • Extract plot display options (return_plotter, return_cpos, savefig, cpos) via kwargs.pop and pass them explicitly to MapdlPlotter.show() across kplot, lplot, aplot, vplot, nplot, eplot, and post plotting methods
  • Reinstate validation in visualizer.show() to prevent both return_plotter and return_cpos being True

Build:

  • Bump ansys-tools-visualization-interface from 0.9.2 to 0.10.0 in project dependencies

Documentation:

  • Add changelog entry for adapting to the new visualizer version

@ansys-reviewer-bot
Copy link
Contributor

Thanks for opening a Pull Request. If you want to perform a review write a comment saying:

@ansys-reviewer-bot review

Copy link
Contributor

sourcery-ai bot commented Jun 20, 2025

Reviewer's Guide

Refactor plotting methods across mapdl and post modules to comply with the 0.10.0 visualizer API by explicitly handling new show() parameters, update the visualizer internals for argument validation, bump the visualization interface dependency, and add a corresponding changelog entry.

Class diagram for updated plotting methods and MapdlPlotter.show()

classDiagram
    class MapdlPlotter {
        +plot(meshes, points, labels, **kwargs)
        +show(return_plotter=False, savefig=None, return_cpos=False, cpos=None, ...)
        +switch_scene(pl)
    }
    class MapdlExtended {
        +kplot(..., **kwargs)
        +lplot(..., **kwargs)
        +aplot(..., **kwargs)
        +vplot(..., **kwargs)
        +nplot(..., **kwargs)
        +eplot(..., **kwargs)
    }
    class Post {
        +_plot_point_scalars(..., **kwargs)
        +_plot_cell_scalars(..., **kwargs)
    }
    MapdlExtended --> MapdlPlotter : uses
    Post --> MapdlPlotter : uses
    MapdlPlotter : +show() now validates return_cpos and return_plotter
    MapdlExtended : +plotting methods now extract show() args explicitly
    Post : +plotting methods now extract show() args explicitly
Loading

Class diagram for show() argument validation logic

classDiagram
    class MapdlPlotter {
        +show(return_plotter, savefig, return_cpos, cpos, ...)
    }
    MapdlPlotter : +show() raises ValueError if return_cpos and return_plotter are both True
Loading

File-Level Changes

Change Details Files
Refactor plot functions to explicitly handle new show() parameters instead of forwarding **kwargs
  • Pop return_plotter, savefig, cpos, and return_cpos from kwargs at start of each plot function
  • Invoke pl.show with explicit named arguments instead of **kwargs
  • Adjust return statements to propagate show() output correctly
src/ansys/mapdl/core/mapdl_extended.py
src/ansys/mapdl/core/post.py
Adjust visualizer internals to perform argument conflict validation in show() and remove redundant checks in plot
  • Remove conflict check for return_cpos and return_plotter from plot()
  • Add ValueError check in show() to prevent both return_cpos and return_plotter being True
  • Eliminate forwarding of unspecified kwargs in show()
src/ansys/mapdl/core/plotting/visualizer.py
Bump ansys-tools-visualization-interface dependency to 0.10.0
  • Update tests dependency version from 0.9.2 to 0.10.0
  • Update docs dependency version from 0.9.2 to 0.10.0
pyproject.toml
Add changelog entry for this fix
  • Create a new changelog file documenting the adapter update
doc/changelog.d/4025.fixed.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added dependencies maintenance General maintenance of the repo (libraries, cicd, etc) bug Issue, problem or error in PyMAPDL labels Jun 20, 2025
Copy link
Collaborator

@germa89 germa89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@AlejandroFernandezLuces
Copy link
Contributor Author

@germa89 just so you know, this PR implies that users won't be able to pass show kwargs directly to PyVista except for the ones I manually exposed: return_cpos, return_plotter, savefig and cpos.

This is caused because plot and show kwargs were being mixed in the visualizer and it causes errors.

@AlejandroFernandezLuces AlejandroFernandezLuces marked this pull request as ready for review June 23, 2025 11:30
@AlejandroFernandezLuces AlejandroFernandezLuces requested a review from a team as a code owner June 23, 2025 11:30
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @AlejandroFernandezLuces - I've reviewed your changes - here's some feedback:

  • There’s a lot of repeated popping of return_plotter, return_cpos, savefig, and cpos in each plot method—consider refactoring that into a shared helper or decorator to reduce duplication and maintenance surface.
  • Add a unit test for the new conflict check in show() to verify that passing both return_plotter=True and return_cpos=True raises the intended ValueError.
  • I noticed inconsistent defaults when popping return_cpos (some methods use None, others False)—unify these defaults across all plot functions to ensure predictable behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- There’s a lot of repeated popping of `return_plotter`, `return_cpos`, `savefig`, and `cpos` in each plot method—consider refactoring that into a shared helper or decorator to reduce duplication and maintenance surface.
- Add a unit test for the new conflict check in `show()` to verify that passing both `return_plotter=True` and `return_cpos=True` raises the intended ValueError.
- I noticed inconsistent defaults when popping `return_cpos` (some methods use `None`, others `False`)—unify these defaults across all plot functions to ensure predictable behavior.

## Individual Comments

### Comment 1
<location> `src/ansys/mapdl/core/post.py:695` </location>
<code_context>
+        return_cpos = kwargs.pop("return_cpos", False)
+        return_plotter = kwargs.pop("return_plotter", False)
+        savefig = kwargs.pop("savefig", None)
+        cpos = kwargs.pop("cpos", False)
         with self._mapdl.save_selection:
             # Select nodes to avoid segfault
</code_context>

<issue_to_address>
Inconsistent default value for 'cpos' parameter.

'cpos' defaults to False here but to None elsewhere. For consistency and to prevent type issues, use None as the default unless False is specifically required.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        cpos = kwargs.pop("cpos", False)
=======
        cpos = kwargs.pop("cpos", None)
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/ansys/mapdl/core/mapdl_extended.py:472` </location>
<code_context>
+            return_plotter = kwargs.pop("return_plotter", False)
+            savefig = kwargs.pop("savefig", None)
+            cpos = kwargs.pop("cpos", None)
+            return_cpos = kwargs.pop("return_cpos", None)
             pl = kwargs.get("plotter", None)
             pl = MapdlPlotter().switch_scene(pl)
</code_context>

<issue_to_address>
Inconsistent default value for 'return_cpos' parameter.

Standardize the default value for 'return_cpos' across all methods, ideally to False, for consistency.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
            return_cpos = kwargs.pop("return_cpos", None)
=======
            return_cpos = kwargs.pop("return_cpos", False)
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

codecov bot commented Jun 23, 2025

Codecov Report

Attention: Patch coverage is 93.87755% with 3 lines in your changes missing coverage. Please review.

Project coverage is 89.14%. Comparing base (53ad87c) to head (6f89e55).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4025      +/-   ##
==========================================
+ Coverage   89.05%   89.14%   +0.09%     
==========================================
  Files         187      187              
  Lines       14970    15002      +32     
==========================================
+ Hits        13331    13373      +42     
+ Misses       1639     1629      -10     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@germa89
Copy link
Collaborator

germa89 commented Jun 25, 2025

Hi @AlejandroFernandezLuces

I left a implementation question in here: ansys/ansys-tools-visualization-interface#306 (comment)

@germa89
Copy link
Collaborator

germa89 commented Jun 25, 2025

Hi @AlejandroFernandezLuces

I left a implementation question in here: ansys/ansys-tools-visualization-interface#306 (comment)

I am going to wait for the next release that implements this comment.

Closing for the moment.

@germa89 germa89 closed this Jun 25, 2025
@germa89 germa89 deleted the fix/new-viz-version branch June 25, 2025 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue, problem or error in PyMAPDL dependencies maintenance General maintenance of the repo (libraries, cicd, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants